﻿Public Class CIRREGULARState4 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CIRREGULARState4.IsEnter")
        If CCommon.isInStr(task.ActionCd, "IRREGULAR") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 実行メソッド
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase
        Dim pdaTask As CPDATask4 = DirectCast(task, CPDATask4)
        Debug.WriteLine("CIRREGULARState4.DoExecute")
        Dim readText As String = task.ProcessText



        Dim stateStatus As Integer = 0

        Select Case readText
            Case CCommon.CNS_RESET4 ''数量変更
                task.ProcessText = ""

                Do While CBarcode.GetBarcodeType(task.ProcessText) <> EnumBarcodeType.INNER_LABEL_CODE
                    If task.ProcessText <> "" Then
                        Dim result As String = ""
                        Dim prevWindowMode As EnumWindowMode
                        Do While result <> "[OK]"
                            If result = "" Then
                                pdaTask.Hardware.alert()
                                prevWindowMode = pdaTask.WindowManager.GetWindowMode()
                                pdaTask.WindowManager.SetAlertMessage(CCommon.CNS_MSG_046, CCommon.COLOR_BLACK, CCommon.COLOR_WHITE)
                                pdaTask.WindowManager.ChangeWindowMode(EnumWindowMode.ALERT_MODE)
                            End If
                            result = task.ReadTextWait(-1)
                        Loop
                        pdaTask.WindowManager.ChangeWindowMode(prevWindowMode)

                        task.ActionCd = "LABEL"
                        task.ProcessText = ""
                        nextState = GetNextState(task)
                        Return nextState

                    End If
                    '' リーダーからデータを取得する(待ち時間制限なし)
                    pdaTask.WindowManager.SetMessage(CCommon.CNS_MSG_062, CCommon.COLOR_BLACK, CCommon.COLOR_GREEN)
                    task.ProcessText = task.ReadTextWait(-1)
                Loop
                readText = task.ProcessText ''社内ラベルコード


                Dim labelType As String = "IN"
                Dim sysItemCd As String = CCommon.TrimCode(readText, CCommon.EnumGetString.LBL_IN_ITEM_CD)
                Dim inBoxQty As Integer = CCommon.From36To10(CCommon.TrimCode(readText, CCommon.EnumGetString.LBL_IN_QTY))
                Dim orderCd As String = ""
                Dim deliveryCd As String = ""
                Dim uniqueCd As String = readText

                Dim befActionQty As Integer = inBoxQty
                Dim actionQty As Integer = 0
                Dim calActionQty As Integer = 0
                If befActionQty = 0 Then
                    ''端数ラベルの場合、入力を求める
                    befActionQty = pdaTask.inputMsg(0, CCommon.CNS_MSG_059, task)
                End If
                actionQty = pdaTask.inputMsg(inBoxQty, CCommon.CNS_MSG_060, task)

                calActionQty = actionQty - befActionQty

                Dim nowDatetime As Date = Now()
                Dim readData As CPDATask4.strctDataList = Nothing
                With readData
                    .correctCd = "1"
                    .empNo = pdaTask.EmpInfo.empNo
                    .orderCd = orderCd
                    .deliveryCd = deliveryCd
                    .sysItemCd = sysItemCd
                    .uniqueCd = uniqueCd
                    .actionQty = calActionQty
                    .befActionQty = 0
                    .actionDate = nowDatetime.ToString("yyyyMMdd")
                    .actionTime = nowDatetime.ToString("HHmmss")
                    .errorCd = "CH"
                    .labelType = labelType

                End With
                pdaTask.listClear()
                pdaTask.addDataList(pdaTask.listView(readData))

            Case Else
                pdaTask.errMsg(CCommon.msgFormat(CCommon.CNS_MSG_058, CCommon.getIrregularCdName(readText)), task)
        End Select

        task.ActionCd = "LABEL"
        task.ProcessText = ""
        'End If
        nextState = GetNextState(task)
        Return nextState
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CIRREGULARState4.DoExit")
        Return True
    End Function

End Class
